package com.sinosoft.hydra.um.services.component.dataCollect.parsers;

import cn.com.sinux.spring.utils.DateUtils;
import com.sinosoft.hydra.logging.LogModules;
import com.sinosoft.hydra.um.constant.BaseConstant;
import com.sinosoft.hydra.um.services.component.dataCollect.DataParser;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/8.
 */
public class Parser implements DataParser {


    public List<String> parse(List<String> cells, Date begin, Date end) {
        Date date;
        try {
            date = DateUtils.parseDate(cells.get(0), BaseConstant.timePatterns);
        } catch (ParseException e) {
            LoggerFactory.getLogger(LogModules.STD_LOGGER).error("日期格式转换失败{}", e.getMessage());
            return null;
        }
        if (begin != null && date.before(begin) || (end != null && date.after(end))) {
            return null;
        }
        return cells;
    }


    public List<String> rendExcelData(List<String> cells) {
        return cells;
    }


    public List<String> rendLineData(List<String> cells) {
        return cells;
    }

    public List<String> getTitles() {
        return Collections.emptyList();
    }


    public boolean valid(List<String> cells) {
        return StringUtils.isNotBlank(cells.get(0));
    }


    public List<Integer> getLineDataCells(int total) {
        return getEffectiveCells(total);
    }


    public List<Integer> getExcelDataCells(int total) {
        return getEffectiveCells(total);
    }


    protected List<Integer> getEffectiveCells(int total) {
        List<Integer> results = new LinkedList<Integer>();
        for (int i = 0; i < total; i++) {
            results.add(i);
        }
        return results;
    }
}
